<template>
  <div class="login">
    <mt-header fixed :title="translate[title]">
      <mt-button  slot="left" icon="back" @click="$router.back()">返回</mt-button>
    </mt-header>
    <div class="login-box">
      <mt-field class="input" label="邮箱" placeholder="请输入邮箱" type="email" v-model="username"></mt-field>
      <mt-field class="input" label="密码" placeholder="请输入密码" type="password" v-model="password"></mt-field>
      <mt-button type="primary" size="large">Join</mt-button>
    </div>
  </div>
</template>
<script>
  import Cookies from 'js-cookie';

  import fetch from '../utils/fetch'

  export default {
    data(){
      return {

        username: '',
        password: '',
        title:'signup',
        translate:{
          login: '登录',
          signup: '注册'
        }
      }
    },
    methods:{
      login(){
        this.validate().then(vali=>{
          fetch.post('https://acfun.leanapp.cn/user/login',{
            username:this.username ,
            password:this.password
          }).then(res=>{
            Cookies.set('userId',res.data.objectId)
          })
        })
      },
      validate(){
        return new Promise((resolve,reject)=>{
          if(this.username!=''&&this.password!=''){
            resolve(true)
          }
          reject('please enter username and password')
        })
      }
    }
  }
</script>
